Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STEP2-4] Add Feature Blocking domains #113

Open
wants to merge 8 commits into
base: sunsun512
Choose a base branch
from

Conversation

sunsun512
Copy link
Collaborator

@sunsun512 sunsun512 commented Mar 11, 2025

변동사항

특정 도메인은 shorten-url 제공을 거부하고 싶어요.

  • csv 파일을 API 통해 업로드 받아서, 해당 파일에 있는 도메인 목록을 서비스 미제공 도메인으로 등록합니다.

@sunsun512 sunsun512 requested a review from Hyune-c March 11, 2025 14:37
@sunsun512 sunsun512 self-assigned this Mar 11, 2025
Copy link
Collaborator

@Hyune-c Hyune-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step 2-2 맞나요? 2-4 같습니다.

public class UrlShortenService {

private final BlackListService blackListService;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service 간 호출이 이루어지고 있네요. service 레이어의 구분에 대해 고민해주세요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BlockedDomainInterface 으로 레이어를 구분했습니다.

@@ -35,6 +38,9 @@ public ShortenUrlDto.Create.Response shortenUrlCreate(ShortenUrlDto.Create.Reque
if (validateOriginUrl(param.getOriginUrl())) {
throw BusinessExceptionGenerator.createBusinessException("DB001");
}
if(isBlocked(param.getOriginUrl())){
throw BusinessExceptionGenerator.createBusinessException("DB004");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 형식이라면 ErrorCode enum 을 매개변수로 받는게 낫지 않나요?

@sunsun512 sunsun512 changed the title [STEP2-2] Add Feature Blocking domains [STEP2-4] Add Feature Blocking domains Mar 11, 2025
- BlockedDomain을 csvv 파일을 업로드 받아서 하는 것으로 변경
- BlockedDomain을 domain layer단으로 변경
…omain

# Conflicts:
#	src/main/resources/application-dev.yml
@sunsun512 sunsun512 requested a review from Hyune-c March 12, 2025 14:27
log.info("file >> {}", file);
csvReaderService.loadBlockedDomains(file);
return ResponseFormatter.ConvertResponse();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST /csv/upload
  • 전 이게 무슨 기능인지 api endpoint 만 봐서는 전혀 유추되지 않습니다.
  • admin 기능에 가까운데 누구나 사용할 수 있는 것 처럼 보입니다.

public interface BlockedDomainInterface {
void loadBlockedDomains(MultipartFile file); // CSV 파일에서 차단 목록 로드
Set<String> getBlockedDomains(); // 차단된 도메인 목록 반환
boolean isBlocked(String url); // 특정 URL이 차단된 도메인인지 확인
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit 전 모든 자료형을 wrapper 로 사용합니다.

import java.util.Set;

public interface BlockedDomainInterface {
void loadBlockedDomains(MultipartFile file); // CSV 파일에서 차단 목록 로드
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. javadoc

Comment on lines +48 to +55
public boolean isBlocked(String url) {
for (String domain : blockedDomains) {
if (url.contains(domain)) {
return true;
}
}
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public boolean isBlocked(String url) {
    return blockedDomains.stream().anyMatch(url::contains);
}

nit

Comment on lines +31 to +34
String line;
while ((line = br.readLine()) != null) {
domainSet.add(line.trim());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        blockedDomains.addAll(br.lines()
                                .map(String::trim)
                                .collect(Collectors.toSet()));

nit

@Service
public class CsvReaderService implements BlockedDomainInterface {

private Set<String> blockedDomains = new HashSet<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. 일급 컬렉션, holder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants